package com.xdap.common.dao;

import com.definesys.mpaas.query.MpaasQuery;
import com.xdap.fsapproval.module.pojo.XdapUsers;
import com.xdap.runtime.service.RuntimeDatasourceService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @BelongsProject：IntelliJ IDEA
 * @BelongsPackage：com.adisseo.service.approval.dao
 * @Author：fei
 * @CreateTime：2022-09-06 12:00
 * @Description: 用户相关查询
 * @Version：1.0
 */
@Repository
@RequiredArgsConstructor
public class FeiShuXdapUserDao {

    public static final String XDAP_MYSQL_PREFIX = "xdap_app_";
    public static final String XDAP_ACTIVITI_PREFIX = "xdap_activiti_";
    private final RuntimeDatasourceService runtimeDatasourceService;

    private MpaasQuery buildQuery() {
        return runtimeDatasourceService.buildTenantNoSchemaMpaasQuery();
    }

    public XdapUsers getXdapUserInfo(String userId, String tenantId, String tableName) {
        return buildQuery()
                .eq("id", userId)
                .table(XDAP_MYSQL_PREFIX + tenantId + "." + tableName)
                .doQueryFirst(XdapUsers.class);
    }

    public List<XdapUsers> getXdapUserInfo(List<String> userIds, String tenantId, String tableName) {
        return buildQuery()
                .in("id", userIds)
                .table(XDAP_MYSQL_PREFIX + tenantId + "." + tableName)
                .doQuery(XdapUsers.class);
    }

}
